package org.darcy.service.impl;

import org.darcy.dao.SysTemplateMapper;
import org.darcy.entity.SysTemplate;
import org.darcy.framework.blog.business.enums.TemplateKeyEnum;
import org.darcy.framework.generic.GenericServiceImpl;
import org.darcy.service.SysTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * 系统模板
 */
@Service
public class SysTemplateServiceImpl extends GenericServiceImpl<SysTemplate> implements SysTemplateService {

	@Autowired
	private SysTemplateMapper sysTemplateMapper;

	/**
	 * 通过key获取模板信息
	 *
	 * @param key
	 * @return
	 */
	@Override
	public SysTemplate getTemplate(TemplateKeyEnum key) {
		return getTemplate(key.toString());
	}

	@Override
	public SysTemplate getTemplate(String key) {
		if (StringUtils.isEmpty(key)) {
			return null;
		}
		QueryWrapper<SysTemplate> q = new QueryWrapper<SysTemplate>();
		q.eq("ref_key", key);
		SysTemplate entity = this.sysTemplateMapper.selectOne(q);
		return entity;
	}

}
